<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 400px;
            border: 1px solid #000;
            margin-bottom: 20px;
        }

        .son {
            width: 0;
            height: 40px;
            background-color: palegreen;
            text-align: center;
            line-height: 40px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="son" id="a">
            <span>0</span><span>%</span>
        </div>
    </div>

    <button>安装</button>
    <span></span>

    <script>
        // 
        var btn = document.querySelector('button')

        var div = document.getElementsByTagName('div')

        var span = document.getElementsByTagName('span')

        var timer = null;

        //
        btn.onclick = function () {
            var num = 0
            if (!timer) {    // 事件第一次执行完了之后  timer就变成了1  所以后面点击事件不会再执行这个定时器
                timer = setInterval(function () {
                    num++
                    div[1].style.width = num + 'px'


                    span[0].innerHTML = Math.ceil(num / 400 * 100)

                    if (num == 400) {
                        clearInterval(timer);
                    }
                }, 10)
            }
        }
    </script>
</body>

</html>